package com.smalldragon.commonUnsafe;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.logging.Logger;

public class TestString2 {

	public static Logger log=Logger.getLogger("test");
	
	public static int clientTotal=5000;
	
	public static int threadTotal=200;
	
	public static StringBuffer stringBuffer=new StringBuffer();
	
	
	public static void main(String[] srgs) throws Exception {
		ExecutorService executorService = Executors.newCachedThreadPool();
		final Semaphore sempher=new Semaphore(threadTotal);
		final CountDownLatch countDownLatch=new CountDownLatch(clientTotal);
		for(int i=0;i<clientTotal;i++) {
			executorService.execute(()->{
				try {
					sempher.acquire();
					add();
					sempher.release();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				countDownLatch.countDown();
			});
		}
		countDownLatch.await();
		executorService.shutdown();
		log.info(""+stringBuffer.length());
	}
	
	
	/*
	 * 
	 */
	public static void add() {
		stringBuffer.append("a");
	}
	
	
}
